package com.daydayup.homework;

import java.util.List;
import java.util.Map;

/**
 * 给出一个数字S，以及一个数组a1...an，要求列出所有S=a1*x1+a2*x2+...+an*xn的所有组合，其中，xn>=0，a1...an均为正数
 * 。示例：输入，S=5，a1=3,a2=2,a3=1，输出，5=1*5,5=2*1+1*3,5=2*2+1*1,5=3*1+1* 2,5=3*1+2*1
 * 
 * @author Administrator
 *
 */
public class Test {
	private static final int[] DATA = { 3, 2, 1 };
	private static final int SUM = 5;

	public static void main(String[] args) {
		for (int i = 0; i < DATA.length; i++) {
			for (int j = 0;; j++) {
				int multiply = DATA[i] * j;
				if (multiply > SUM) {
					break;
				}
			}
		}
	}

	public static Integer sum(int index, List<Map<String, Integer>> l) {
		Integer value = 0;
		for (int i = index; i < l.size(); i++) {
			int sum = 0;
			Map<String, Integer> multiplys = l.get(i);
			for (String multiply : multiplys.keySet()) {
				value = multiplys.get(multiply);
				sum = value + sum(i + 1, l);
				if (sum == SUM) {
					System.out.println(multiply);
				}
			}
		}
		return value;
	}
}
